<template>

  <div class=".app-container " >
    <div style="height:20px"></div>
    <el-form :model="queryParams" ref="queryForm"   v-show="showSearch" label-width="68px">
      <el-row>
        <el-col span="5" :xs="12">
          <el-form-item label="所属机构" >
            <treeselect v-model="queryParams.projectAffiliation" :options="deptOptions" :shpw-count="true" placeholder="请选择所属机构"></treeselect>
          </el-form-item>
        </el-col>
        <el-col span="5" :xs="12" offset="1">
          <el-form-item label="项目编号" prop="projectItermNum">
            <el-input
              v-model="queryParams.projectItermNum"
              placeholder="请输入项目编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col span="5" :xs="12" offset="1">
          <el-form-item label="项目名称" prop="projectName">
            <el-input
              v-model="queryParams.projectName"
              placeholder="请输入项目名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col span="5" :xs="12" offset="1">
          <el-form-item label="项目性质" prop="projectNature"  >
            <el-select v-model="queryParams.projectNature" placeholder="请选择" clearable  @keyup.enter.native="handleQuery">
              <el-option label1="新建项目" value="新建项目"></el-option>
              <el-option label1="扩建项目" value="扩建项目"></el-option>
              <el-option label1="改建项目" value="改建项目"></el-option>
              <el-option label1="迁建项目" value="迁建项目"></el-option>
              <el-option label1="恢复项目" value="恢复项目"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col span="5" :xs="12">
          <el-form-item label="项目状态" prop="projectStatus"  >
            <el-select v-model="queryParams.projectStatus" placeholder="请选择" clearable  @keyup.enter.native="handleQuery">
              <el-option label="所有" ></el-option>
              <el-option label="正常" value=0></el-option>
              <el-option label="停用" value=1></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col span="5" :xs="12" offset="1">
          <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery" >搜索</el-button>
          <el-button type="primary" plain icon="el-icon-plus" size="medium" @click="handleAdd" v-hasPermi="['xmsts:promanage:add']">新增</el-button>

        </el-col>
      </el-row>
      <!-- 折叠区域 -->
      <el-collapse v-model="activeNames" @change="handleChange">
        <el-row>
          <el-collapse-item title="折叠数据区域" name="1" class="numpac" align="center" style="margin-left:20px" text-aline="right">
            <div style="display: flex; margin-top:20px; height: 120px;">
              <transition name="el-zoom-in-center">
                <div  class="transition-box">
                  <div style="height:20px "></div>
                  <div > <el-pagination
                    layout="total"
                    :total="total">
                  </el-pagination>
                  </div>
                  <div style="height:20px "></div>
                  <div >项目总数</div>
                </div>
              </transition>

              <transition name="el-zoom-in-top">
                <div class="transition-box">
                  <div style="height:20px "></div>
                  <div >0</div>
                  <div style="height:20px "></div>
                  <div >生产设施总数</div>
                </div>
              </transition>

              <transition name="el-zoom-in-bottom">
                <div  class="transition-box">
                  <div style="height:20px "></div>
                  <div >0</div>
                  <div style="height:20px "></div>
                  <div >关键装置重点部位总数</div>
                </div>
              </transition>
              <transition name="el-zoom-in-bottom" >
                <div  class="transition-box" style="width:500px " >
                  <el-row>

                    <el-col span="11" :xs="12" offset="1" >
                      <div style="height:5px "></div>
                      <el-form-item label="提前提醒">
                        <el-select v-model="form.a" placeholder="请选择">
                          <el-option label="近一周" value=0></el-option>
                          <el-option label="近两周" value=1></el-option>
                          <el-option label="近一月" value=2></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col span="12" :xs="12" >
                      <p>待检查设施数：0</p>
                      <p>待检测设施数：0</p>
                      <p>待保养设施数：0</p>
                    </el-col>
                  </el-row>


                </div>
              </transition>
            </div>
          </el-collapse-item>
        </el-row>
      </el-collapse>
    </el-form>

    <!-- 显示详情 -->
    <el-drawer size="48%"  :visible.sync="dialog" direction="rtl"   >
      <el-descriptions title="项目详细信息" size="medium" :cloumn=2 border >
        <el-descriptions-item label="项目编号" prop="departmentsName">{{form.projectItermNum}} </el-descriptions-item>
        <el-descriptions-item label="项目名称" prop="workshopName">{{form.projectName}} </el-descriptions-item>
        <el-descriptions-item label="项目性质" prop="floorSpace">{{form.projectNature}} </el-descriptions-item>
        <el-descriptions-item label="项目总投资" prop="floorSpace">{{form.projectInvestment}} </el-descriptions-item>
        <el-descriptions-item label="项目建设单位" prop="layerNumber">{{form.projectConstructionUnit}} </el-descriptions-item>
        <el-descriptions-item label="项目建设地点" prop="buildingStructure">{{form.projectConstructionLocation}} </el-descriptions-item>
        <el-descriptions-item label="项目进展情况" prop="dangerLevel">{{form.projectProgress}} </el-descriptions-item>
        <el-descriptions-item label="项目开工日期" prop="buildingStructure">{{form.projectCommencementDate}} </el-descriptions-item>
        <el-descriptions-item label="项目竣工验收日期" prop="buildingStructure">{{form.projectCompletionAcceptanceDate}} </el-descriptions-item>
        <el-descriptions-item label="安全设施三同时" prop="buildingStructure">{{form.threeSafetyFacilities}} </el-descriptions-item>

      </el-descriptions>
    </el-drawer>


    <!-- 表格数据 -->




    <div label-width="900px">

      <el-table v-loading="loading"
                :data="managementList"
                border
                :default-sort="{prop: 'projectStatus'}"
                max-height="350"

      >

        <el-table-column label="所属机构" align="center" prop="dept.deptName" width="200"/>
        <el-table-column label="项目编号" align="center" prop="projectItermNum" width="200"/>
        <el-table-column label="项目名称" align="center" prop="projectName" width="200"/>
        <el-table-column label="项目性质" align="center" prop="projectNature" width="200"/>
        <el-table-column label="项目建设单位" align="center" prop="projectConstructionUnit" width="200" />
        <el-table-column label="项目总投资" align="center" prop="projectInvestment" width="200"/>
        <el-table-column prop="projectStatus" label="状态" sortable align="center" width="200">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.projectStatus==0">正常</el-tag>
            <el-tag type="danger" v-if="scope.row.projectStatus==1">停用</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right"  width="150" >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['xmsts:promanage:edit']"
            >编辑</el-button>
            <!-- 查看详情 -->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-look"
              @click="handelOpen(scope.row)"
              v-hasPermi="['xmsts:promanage:query']"
            >查看</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['xmsts:promanage:remove']"
            >删除</el-button>

          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px"  append-to-body text-aline="right" >

      <el-form ref="form" :model="form" :rules="rules" label-width="130px"   >

        <el-form-item label="所属机构"  prop="projectAffiliation">
          <treeselect v-model="form.projectAffiliation" :options="deptOptions" :shpw-count="true" placeholder="请选择所属机构"></treeselect>
        </el-form-item>
        <el-form-item label="项目编号" prop="projectItermNum">
          <el-input v-model="form.projectItermNum" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目性质">
          <el-select v-model="form.projectNature" placeholder="请选择">
            <el-option label1="新建项目" value="新建项目"></el-option>
            <el-option label1="扩建项目" value="扩建项目"></el-option>
            <el-option label1="改建项目" value="改建项目"></el-option>
            <el-option label1="迁建项目" value="迁建项目"></el-option>
            <el-option label1="恢复项目" value="恢复项目"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目建设单位" prop="projectConstructionUnit">
          <el-input v-model="form.projectConstructionUnit" placeholder="请输入项目建设单位" />
        </el-form-item>
        <el-form-item label="项目总投资" prop="projectInvestment">
          <el-input v-model="form.projectInvestment" placeholder="请输入项目总投资" />
        </el-form-item>
        元
        <el-form-item label="项目建设地点" prop="projectConstructionLocation">
          <el-input v-model="form.projectConstructionLocation" placeholder="请输入项目建设地点" />
        </el-form-item>
        <el-form-item label="项目进展情况" prop="projectProgress">
          <el-input v-model="form.projectProgress" placeholder="请输入项目进展情况" />
        </el-form-item>
        <el-form-item label="项目开工日期" prop="projectCommencementDate">
          <el-date-picker clearable
                          v-model="form.projectCommencementDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择项目开工日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目竣工验收日期" prop="projectCompletionAcceptanceDate">
          <el-date-picker clearable
                          v-model="form.projectCompletionAcceptanceDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择项目竣工验收日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="安全设施三同时" prop="threeSafetyFacilities">
          <el-input v-model="form.threeSafetyFacilities" placeholder="请输入安全设施三同时" />
        </el-form-item>

        <el-form-item label="项目描述" prop="projectDescription" style="width: 100%">
          <el-input v-model="form.projectDescription" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="上传附件" prop="projectAttachment">
          <el-upload ref="projectAttachment"
                     :file-list="manageList"
                     :action="field101Action"
                     :before-upload="field101BeforeUpload">
            <el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
          </el-upload>
        </el-form-item>
        <!-- 单选框 -->
        <el-form-item label="状态" prop="projectStatus">
          <el-radio v-model="form.projectStatus" label="1">停用</el-radio>
          <el-radio v-model="form.projectStatus" label="0">启用</el-radio>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listManagement, getManagement,  addManagement, updateManagement,delManagement,getDeptList,handleNum} from "@/api/system/projectmanage";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";


export default {
  components: { Treeselect },
  name: "promanage",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //表格数据
      managementList: [],
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      // 部门名称
      deptName: undefined,
      // 是否显示弹出层
      open: false,
      //抽屉
      dialog: false,
      // 上传参数
      projectAttachment: undefined,
      upload: {
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/file/upload",
        // 上传的文件列表
        fileList: []
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectNature: null,
        projectConstructionUnit: null,
        projectInvestment: null,
        projectConstructionLocation: null,
        projectProgress: null,
        projectCommencementDate: null,
        projectCompletionAcceptanceDate: null,
        threeSafetyFacilities: null,
        projectDescription: null,
        projectAttachment: null,
        projectStatus: null,
        projectAffiliation: undefined
      },

      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectAffiliation: [
          { required: true, message: "'所属机构'是必填项。", trigger: "blur" }
        ],
        projectItermNum: [
          { required: true, message: "'项目编号'是必填项。", trigger: "blur" }
        ],
        projectName: [
          { required: true, message: "'项目名称'是必填项。", trigger: "blur" }
        ],
        projectNature: [
          { required: true, message: "'项目性质'是必填项。", trigger: "blur" }
        ],
        projectConstructionUnit: [
          { required: true, message: "'项目建设单位'是必填项。", trigger: "blur" }
        ],
        projectInvestment: [
          { required: true, message: "'项目总投资'是必填项。", trigger: "blur" }
        ],
        projectConstructionLocation: [
          { required: true, message: "'项目建设地点'是必填项。", trigger: "blur" }
        ],
        field101Action: 'https://jsonplaceholder.typicode.com/posts/',
        field101fileList: [],
      },


    };
  },
  created() {
    this.getList();
    this.getDeptTree();
  },
  computed: {},
  watch: {},
  mounted() {},
  methods: {
    getDeptTree() {
      getDeptList().then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listManagement(this.queryParams).then(response => {
        this.managementList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      handleNum().then(response =>{
      this.num = response.number
      })
    },
   
    // 取消按钮
    cancel(){
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        projectId: null,
        projectName: null,
        projectNature: null,
        projectConstructionUnit: null,
        projectInvestment: null,
        projectConstructionLocation: null,
        projectProgress: null,
        projectCommencementDate: null,
        projectCompletionAcceptanceDate: null,
        threeSafetyFacilities: null,
        projectDescription: null,
        projectAttachment: null,
        projectStatus: "0",
        projectAffiliation: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },


    /**显示详细信息*/
    handelOpen(row) {
      this.reset();
      const projectId = row.projectId
      getManagement(projectId).then(response => {
        this.form = response.data;
        this.dialog = true
        infoList_detial(scope.row.projectId)
      });

    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open=true;
      this.title = "新建";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open=true;
      const projectId = row.projectId
      getManagement(projectId).then(response => {
        this.form = response.data;
        this.title = "修改";
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const projectIds = row.projectId || this.ids
      this.$modal.confirm('是否确认删除项目编号为"' + row.projectItermNum + '"的数据项？').then(function() {
        return delManagement(projectIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.projectId != null) {
            updateManagement(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addManagement(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 文件上传成功处理
    field101BeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 2
      if (!isRightSize) {
        this.$message.error('文件大小超过 2MB')
      }
      return isRightSize
    },

  }
};

</script>
<style>
.numpac{
  padding: 0px;

}

.el-upload__tip {
  line-height: 1.2;
}





.transition-box {
  margin-bottom: 0px;
  width: 280px;
  height: 120px;
  border-radius: 4px;
  background-color:rgba(29, 10, 131, 0.067);
  text-align: center;

  padding: 0px;
  box-sizing: border-box;
  margin-right: 20px;
}
</style>
